<extend name="Extends/base" />
<block name="title">编辑广告</block>
<block name="css">
</block>
<block name="body_style">class="bgc-f2f4f6"</block>
<block name="body">
    <div class="bgc-f3f3f3 ptb5 plr20 c-border-tb clearfix">
        <b class="c-f16" style="line-height: 40px">编辑广告</b>
        <a href="javascript:;" class="jump-href fr c-btn c-btn-ghost-green c-btn-rounded ml10">刷新</a>
        <a href="javascript:history.back(-1);" class="fr c-btn c-btn-ghost-green c-btn-rounded ml10">返回</a>
    </div>
    <div class="pt30 plr20">
        <form id='myForm'>
            <input type="hidden" id="id" value="{$info.id}" />
            <div class="form-layout form-horizontal-wider">
                <div class="control-group mb10">
                    <label class="control-label"><sub class="control-sub"></sub> 广告名称：</label>
                    <div class="control-form">
                        <input type="text" name="title" placeholder="请输入广告名称" value="{$info.title}"
                            class="input-text input-text-w350">
                    </div>
                </div>
                <div class="control-group mb10">
                    <label class="control-label"><sub class="control-sub"></sub> 广告类型：</label>
                    <div class="control-form">
                        <div class="cus-sel cus-sel-h33" data-toggle="formSelect">
                            <div class="cus-sel-chosed">
                                <input type="text" name="ad_type" value="{$info.ad_type}" style="display:none;">
                                <span class="cus-sel-chosed-txt" data-value="">
                                    <if condition="$info['ad_type'] eq 1">
                                        首页轮播
                                        <elseif condition="$info['ad_type'] eq 2" />
                                        任务赚轮播
                                        <else />
                                        -请选择-
                                    </if>
                                </span>
                                <span class="jselect-icon"></span>
                            </div>
                            <div class="cus-sel-list" style="display: none;">
                                <ul>
                                    <li class="empty-sel"><a href="javascript:;" data-value="">-请选择-</a></li>
                                    <li><a href="javascript:;" data-value="1">首页轮播</a></li>
                                    <li><a href="javascript:;" data-value="2">任务赚轮播</a></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="control-group mb10">
                    <label class="control-label"><sub class="control-sub"></sub> 广告图片：</label>
                    <div class="control-form">
                        <if condition="$info['cover']">
                            <img src='{$info.cover}' class='upload-file-btn' height='100' width='100'>
                            <else />
                            <span class="upload-file-btn c-btn c-btn-small c-btn-green">浏览</span>
                        </if>
                    </div>
                </div>

                <div class="control-group mb10">
                    <label class="control-label"><sub class="control-sub"></sub> 广告链接：</label>
                    <div class="control-form">
                        <input type="text" name="url" placeholder="链接" value="{$info.url}" class="input-text">
                    </div>
                </div>
                <div class="control-group mb10">
                    <label class="control-label"><sub class="control-sub"></sub> 排序：</label>
                    <div class="control-form">
                        <input type="number" name="sort" value="{$info.sort}" placeholder="排序" class="input-text">
                    </div>
                </div>
            </div>
        </form>
        <div class="mt20">
            <a class="edit-btn c-btn c-btn-blue">提交</a>
        </div>
    </div>
</block>
<block name="js">
    <script type="text/javascript" src="__CST__/js/api.ad.js?v={:C('JS_CSS_VERSION')}"></script>
    <script type="text/javascript" src="__CST__/js/imgUpload.js?v={:C('JS_CSS_VERSION')}"></script>
    <script type="text/javascript">
        var currId = "{$id}";
        $(function () {

        });


        $('.edit-btn').on('click', function () {
            var data = getSeachData();
            data.cover = $('.upload-file-btn').attr('src');
            doEditAd(currId, data, function (res) {
                if (res.Code != 10000) {
                    $.toast(res.Message);
                    return false;
                }

                var url = $.sUrl("/Console/Ad/adList");
                location.href = url;
            });
        });
        /**
         * 获取搜索的数据
         * @returns {{}}
         */
        function getSeachData() {
            var fromData = $('#myForm').serializeArray();
            var data = {};
            $.each(fromData, function () {
                var name = this.name;
                var value = $.trim(this.value);
                if (value) {
                    data[name] = value;
                }
            });
            return data;
        }
        //点击上传图片
        $(document).on('click', '.upload-file-btn', function () {
            var $t = $(this);
            $.imgUpload(function (res) {
                if (res.Code != 10000) {
                    $.toast(res.Message);
                    return false;
                }

                var url = res.Result;
                $t.parent().html("<img src='" + url +
                    "' class='upload-file-btn' height='100' width='100'>");
            });
        });
    </script>
</block>